package orders

class Orders {
    int  cherry
    int curlyMaple
    int genuineMagohany
    int wenge
    int whiteOak
    int sawDust
    String buyerName
    String adress
    
    int timeDelivery
    int price
    
    static constraints = {
		buyerName blank: false, size: 3..35, unique: true
    }

    def calculateDeliveryTime (){
        List t = [shippingTime(cherry, 0.5),shippingTime(curlyMaple, 1.5),shippingTime(genuineMagohany, 3),
        shippingTime(wenge, 5), shippingTime(whiteOak, 1)]
        timeDelivery = t.max()
    }
    
    def calculatePrice(){
        List t = [(cherry *5.95),(curlyMaple*6),(genuineMagohany*9.60),(wenge*22.35), (whiteOak*1),(sawDust*1.5) ]
        price = t.sum();
    }
    
    def shippingTime(amount, deliveryTime){
        if (amount <= 100 && amount >0 ) return deliveryTime
        if (amount <= 200 && amount >100 ) return deliveryTime*2
        if (amount <= 300 && amount >200 ) return deliveryTime*3
        if (amount <= 400 && amount >300 ) return deliveryTime*4
        if (amount <= 500 && amount >400 ) return deliveryTime*5
        if (amount <= 1000 && amount >500 ) return deliveryTime*5.5
    }
    
}
